package indi.wshape1.takeawaydeliveryinfo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import indi.wshape1.takeawaydeliveryinfo.mapper.GroupMapper;
import indi.wshape1.takeawaydeliveryinfo.pojo.Group;
import indi.wshape1.takeawaydeliveryinfo.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Wshape1
 * @description 针对表【group】的数据库操作Service实现
 * @since 2023-01-17 12:57:25
 */
@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group>
        implements GroupService {

    @Autowired
    @SuppressWarnings("all")
    private GroupMapper groupMapper;

    public List<String> getGroupNameByBlockName(String blockName) {
        if (blockName == null)
            return groupMapper.selectGroupNameList();
        return groupMapper.selectGroupNameByBlockName(blockName);
    }

    @Override
    public List<Group> getListByBlockNameAndKeyword(String blockName, String keyword) {

        QueryWrapper<Group> queryWrapper = new QueryWrapper<>();
        queryWrapper.and((q) ->
                        q.like("group_name", keyword).or()
                                .like("info", keyword).or()
                                .like("block_name", keyword))
                .ne("group_name", "null");

        if (blockName != null) {
            queryWrapper.eq("block_name", blockName);
        }
        return list(queryWrapper);
    }

    @Override
    public int removeBatchByBlockIds(List<Integer> ids) {
        return groupMapper.deleteBatchByBlockIds(ids);
    }

}




